export default async function requestMsg(toTarget,lastTime,location) {

	const user =getApp().globalData.user
	
    // 类型检查
    if (user === null||location===null) {
        throw new Error('requestMsg参数未准备完成');
    }
    const app = getApp();
    const ws = app.globalData.ws;
    // 更严格的检查
    if (!ws) {
        throw new Error('WebSocket 对象未定义，请确保 WebSocket 已正确初始化');
    }
    try {
	
        const query = {
            sendUserId: user.userId,
            userTel: user.userTel,
            location: location,
            toTarget: toTarget,
            nicPic: user.nicPic,
            nicName: user.nicName,
            receiveDistance: getApp().globalData.receiveDistance,
            lastTime: lastTime||0,
            isRequest: true
        };
   
   await  ws.send({
			data: JSON.stringify(query), 
			
            });

        return true; // 发送成功
    } catch (e) {

        throw e; // 将错误抛出给调用者
    }
}